package com.caiyouxi.goods.controller;

import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.control.BaseController;
import com.caiyouxi.goods.model.GoodsDiscount;
import com.caiyouxi.goods.model.GoodsInfo;
import com.caiyouxi.goods.service.GoodsDiscountsService;
import com.caiyouxi.goods.service.GoodsInfoService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by Administrator on 2017/11/9.
 */

@RestController
@RequestMapping("/boss/goods_discounts")
public class GoodsDiscountsController extends BaseController {

    private Logger logger = Logger.getLogger(GoodsDiscountsController.class);

    @Autowired
    private GoodsDiscountsService goodsDiscountsService;
    @Autowired
    private GoodsInfoService goodsInfoService;

    /**
     * 查询商品折扣设置
     */
    @RequestMapping("get_goods_discounts_info")
    public ResData get_goods_discounts_info(HttpServletRequest request, HttpServletResponse response, @RequestBody GoodsDiscount goodsDiscount){
        logger.info("=============================== 查询商品折扣设置 ================================");
        return goodsDiscountsService.get_goods_discounts_info(goodsDiscount);
    }

    /**
     * 查询商品折扣设置列表
     */
    @RequestMapping("/get_goods_discounts_list")
    public ResData get_goods_discounts_list(HttpServletRequest request,HttpServletResponse response,@RequestBody GoodsDiscount goodsDiscount){
        logger.info("=============================== 查询商品折扣设置列表================================");
        return goodsDiscountsService.get_goods_discounts_list(goodsDiscount);
    }

    /**
     * 新增商品折扣设置
     */
    @RequestMapping("add_goods_discounts")
    public ResData add_goods_discounts(HttpServletRequest request,HttpServletResponse response,@RequestBody GoodsDiscount goodsDiscount){
        logger.info("=============================== 新增商品折扣设置 ================================");
        return goodsDiscountsService.add_goods_discounts(goodsDiscount);
    }

    /**
     * 修改商品折扣设置
     */
    @RequestMapping("update_goods_discounts")
    public ResData update_goods_discounts(HttpServletRequest request,HttpServletResponse response,@RequestBody GoodsDiscount goodsDiscount){
        logger.info("=============================== 修改商品折扣设置 ================================");
        return  goodsDiscountsService.update_goods_discounts(goodsDiscount);
    }

    /**
     * 删除商品折扣设置
     */
    @RequestMapping("delete_goods_discounts")
    public ResData delete_goods_discounts(HttpServletRequest request,HttpServletResponse response,@RequestBody GoodsDiscount goodsDiscount){
        logger.info("=============================== 删除商品折扣设置 ================================");
        return goodsDiscountsService.delete_goods_discounts(goodsDiscount) ;
    }

    /**
     * 获取对应的用户可用的商品折扣
     */
    @RequestMapping("get_goods_discounts_usefull_list")
    public ResData get_goods_discounts_usefull_list(HttpServletRequest request,HttpServletResponse response,@RequestBody GoodsInfo gInfo){
        logger.info("=============================== 删除商品折扣设置 ================================");
        GoodsInfo goods = goodsInfoService.select_goodsInfo_by_id(gInfo.getId());
        List<GoodsDiscount> goods_discount = goodsDiscountsService.get_goods_discounts_usefull_list(goods) ;
        return success(goods_discount);
    }
}
